﻿////////////////////////////////////////////////////////////////
///
/// File: TempExp.cs
/// Author: Lucio Davide Spano
/// Last update: 27 July 2012
/// Description: This file contains the basic class for 
///              building temporal gesture expressions
/// To do: 
/// ------------------------------------------------------------
/// Copyright (c) 2012 Lucio Davide Spano 
///                     (lucio.davide.spano@isti.cnr.it)
/// 
/// The use and distribution terms for this software are 
/// contained in the file named license.txt, which can be found 
/// in the root of this distribution.
/// By using this software in any fashion, you are agreeing to 
/// be bound by the terms of this license.
///
/// You must not remove this notice, or any other, from this
/// software.
/// ------------------------------------------------------------
////////////////////////////////////////////////////////////////


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GestIT
{
    public delegate void StateChangedHandler(TmpExp sender, ExpEventArgs args, Token token);
    internal delegate void NotAcceptedToken(TmpExp sender, SimpleTmpExp originalSender, ExpEventArgs args, Token token);
    public class TmpExp
    {
       
        internal event StateChangedHandler OnStateChanged;
        internal event NotAcceptedToken OnNotAcceptedToken;
        public event StateChangedHandler Completed;
        public event StateChangedHandler Error;
        public event StateChangedHandler Performing;

        public ExecState State 
        { 
            get {return state;}
        }

        public TmpExp Parent { get; internal set; }
        public bool Iterative { get; set; }
        public bool Optional { get; set; }
        public ExpType Type
        {
            get { return type; }
        }

        protected ExecState state;
        protected ExpType type;

        public TmpExp()
        {
            this.state = ExecState.Disabled;
            this.Parent = null;
            this.Iterative = false;
            this.Optional = false;
            this.type = ExpType.Simple;
            
        }

        public virtual void SetExectState(ExecState state, Token token)
        {
            this.state = state;
        }

        public virtual bool Accepts(ExpEventArgs args)
        {
            return false;
        }

        internal void RaiseOnStateChanged(TmpExp sender, ExpEventArgs args, Token token)
        {
            if (OnStateChanged != null)
            {
                OnStateChanged(sender, args, token);
            }
        }

        internal void RaiseCompleted(TmpExp sender, ExpEventArgs args, Token token)
        {
            if (Completed != null)
            {
                Completed(sender, args, token);
            }
        }

        internal void RaiseError(TmpExp sender, ExpEventArgs args, Token token)
        {
            if (Error != null)
            {
                Error(sender, args, token);
            }
        }

        internal void RaisePerforming(TmpExp sender, ExpEventArgs args, Token token)
        {
            if (Performing != null)
            {
                Performing(sender, args, token);
            }
        }

        internal void RaiseOnNotAcceptedToken(SimpleTmpExp originalSender, ExpEventArgs args, Token token)
        {
            if (OnNotAcceptedToken != null)
            {
                OnNotAcceptedToken(this, originalSender, args, token);
            }
        }

    }

    public enum TmpOperator
    {
        ImmediateChoice,
        Choice,
        Enabling,
        SynchronizedParallel,
        Parallel,
        Disabling,
        OrderIndependence,
        None
    }

    public enum ExecState
    {
        Disabled,
        Completed,
        Enabled,
        Performing,
        Error
    }

    public enum ExpType
    {
        Simple,
        Binary,
        Complex
    }
}
